<template>
  <view class="login">
    <image src="../../static/imgs/Frame 1510.png" mode=""></image>
    <view class="login_content">
      <view class="title">登录</view>

      <!-- 账号登录 -->
      <view class="zhlogin">
        <view class="zhlogin_title">账号登录</view>
        <view class="zhlogin_xcx">开芯网商城小程序端</view>

        <input type="text" placeholder="请输入手机号">
        <input type="password" placeholder="请输入密码">

        <view class="specification">
          <radio value="radio" />
          <text>登陆前详细阅读</text>
          <text class="agreement">《开芯网用户协议》</text>
          <text>和</text>
          <text class="agreement">《隐私协议》</text>
        </view>

        <button class="button">登录账号</button>

        <view class="sign_in">
          <text>立即注册</text>
          <text>忘记密码</text>
        </view>
      </view>

      <!--  -->
      <view class="dsf">
        <view class="gang"></view>
        <view class="zi">第三方登录</view>
        <view class="gang"></view>
      </view>
      <view class="zj" @click="GetWxOpenid()">
        <image src="../../static/ximg/xm (29).png"></image>
      </view>
    </view>
  </view>

</template>

<script>
  import {
    request
  } from "@/request/index.js"
  import regeneratorRuntime from '@/lib/runtime/runtime';
  import {
    login
  } from "@/utils/asyncWx.js"
  export default {
    data() {
      return {
        radio: '',
        xz: true,
        username: '',
        password: '',
        hobby: [{
          text: '',
          value: 0
        }, ],
        openid: ""
      }
    },
    methods: {

      async GetWxOpenid() {
        var code_res = await login()
        if (code_res.errMsg == "login:ok") {
          uni.showLoading({
            title: '加载中',
            mask: true
          })
          var res = await request({
            url: 'wxlogin',
            data: {
              code: code_res.code
            }
          })
          if (res.code == 0) {
            this.openid = JSON.parse(res.data).openid;
            this.WxLogin();

          }




        }
        // console.log(code)

      },


      //  微信登录
      async WxLogin() {
        var res = await request({
          url: 'GetWxLogin',
          data: {
            openid: this.openid
          }
        })
        uni.hideLoading()
        if (res.code == 0) {
          uni.showToast({
            icon: 'none',
            title: res.msg
          })
          wx.setStorageSync("token", res.data.token);
          setTimeout(() => {
            uni.switchTab({
              url: "/pages/index/index"
            })
          }, 2000)

        } else {
          uni.showToast({
            icon: 'none',
            title: res.msg
          })
        }
      },


      // 注册
      GetReg() {
        uni.navigateTo({
          url: '/pages/login/reg'
        });
      },

      // 忘记密码
      GetForget() {
        uni.navigateTo({
          url: '/pages/login/forget'
        });
      },

      hu() {
        this.xz = !this.xz
      },
      async getlogin() {

        if (this.xz == false) {
          uni.showToast({
            icon: 'none',
            title: '请阅读用户协议与隐私政策'
          })
          return
        }
        if (this.username == '' || this.password == '') {
          uni.showToast({
            icon: 'none',
            title: '请输入用户名或密码'
          })
          return

        }

        let datas = {
          username: this.username,
          password: this.password,
        }

        var res = await request({
          url: "Getlogins",
          method: "post",
          data: datas
        });

        if (res.code == 0) {
          uni.showToast({
            title: res.msg,
            icon: "success",
            duration: 1500,
            success: () => {
              wx.setStorageSync("token", res.data.token);
              if (res.data.openid == null) {
                uni.navigateTo({
                  url: "/pages/login/start"
                })
              } else {
                uni.switchTab({
                  url: '/pages/my/my'
                });
              }

            }
          })
        } else {
          uni.showToast({
            title: res.msg,
            icon: "none",
            duration: 1500,
          })

        }

        // if (this.xz == true) {
        // 	uni.switchTab({
        // 		url: '/pages/index/index'
        // 	});
        // }
      }
    }
  }
</script>

<style scoped lang="scss">
  page {
    background-color: white;
  }

  .login {
    position: relative;

    >image {
      width: 100%;
      height: 1060rpx;
    }
  }

  .login_content {
    position: absolute;
    top: 108rpx;
    width: 100%;
  }

  .title {
    width: 100%;
    text-align: center;
    font-size: 34rpx;
    margin-bottom: 100rpx;
    // margin-top: 108rpx;
  }

  // 账号登陆
  .zhlogin {
    padding: 50rpx;

    input {
      padding: 40rpx 10rpx;
      border: 2rpx solid #EEEEEE;
    }

    .zhlogin_title {
      font-size: 48rpx;
      font-weight: bold;
      color: #333333;
      margin-bottom: 22rpx;
    }

    .zhlogin_xcx {
      font-size: 24rpx;
      font-weight: 500;
      color: #666666;
      margin-bottom: 100rpx;
    }

    .data-v-b237504c .u-border-bottom {

      padding: 20rpx 0;
    }

    // 说明书
    .specification {
      margin-top: 44rpx;
      margin-bottom: 40rpx;

      radio {
        // vertical-align: middle;
        margin-right: 20rpx;
      }

      >text {
        font-size: 24rpx;
        font-weight: 400;
        color: #333333;
        line-height: 24rpx;
      }

      .agreement {
        color: #3369FF;
      }

    }

    .button {
      width: 650rpx;
      height: 84rpx;
      color: #FFFFFF;
      background: #3369FF;
      border-radius: 42rpx 42rpx 42rpx 42rpx;
    }

    .sign_in {
      margin-top: 40rpx;
      padding: 0 40rpx;
      display: flex;
      justify-content: space-between;

      >text {

        font-size: 24rpx;
        font-weight: 500;
        color: #999999;
      }
    }
  }

  // 
  .dsf {
    width: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    margin-top: 242rpx;
  }

  .gang {
    width: 30%;
    border-bottom: 2rpx solid #999999;
  }

  .zi {
    margin: 0 20rpx;
    color: #666666;
    font-size: 32rpx;
  }

  .zj {

    margin: 0 auto;
    margin-top: 60rpx;
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;

    image {
      width: 100%;
      height: 100%;
    }
  }
</style>